<?php
/**
 * Database Setup.
 *
 * @package WP cr mobile
 */
class CRMobile_DatabaseSetup
{
    public function __construct() {}

    public function createTables()
    {
        global $wpdb;
        $company_table = $wpdb->prefix . "cr_mobile_companies";       
        $review_table  = $wpdb->prefix . "cr_mobile_reviews";		

        $sql = "CREATE TABLE $company_table (
            ID INT AUTO_INCREMENT NOT NULL,
            name VARCHAR(255) NOT NULL,
            url VARCHAR(255) DEFAULT '' NOT NULL,
            moderator INT DEFAULT 0 NOT NULL,
            star VARCHAR(255) DEFAULT '' NOT NULL,
            theme VARCHAR(255) DEFAULT '' NOT NULL,
            exclude TEXT NOT NULL,
            threshold INT DEFAULT 0 NOT NULL,
            intro TEXT NOT NULL,
            thanks TEXT NOT NULL,
            emails TEXT NOT NULL,
            coupon VARCHAR(255) DEFAULT '' NOT NULL,
            logo VARCHAR(255) DEFAULT '' NOT NULL,
            sharing INT DEFAULT 0 NOT NULL,
            optin_service VARCHAR(255) DEFAULT '' NOT NULL,
            optin_address VARCHAR(255) DEFAULT '' NOT NULL,
            sms TINYINT(1) DEFAULT 0 NOT NULL,
            sms_keyword VARCHAR(255) DEFAULT '' NOT NULL,
            social TEXT NOT NULL,
            PRIMARY KEY ID (ID)
        );";
        $sql .= "CREATE TABLE $review_table (
            ID INT AUTO_INCREMENT NOT NULL,
            company_id INT NOT NULL,
            reviewer_name VARCHAR(255) NOT NULL,
            reviewer_email VARCHAR(255) NOT NULL,
            review_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
            rating INT DEFAULT 0 NOT NULL,
            review TEXT NOT NULL,
            status VARCHAR(255) NOT NULL,
            PRIMARY KEY ID (ID)
        );";

        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($sql);
    }

    public function dropTables()
    {
        global $wpdb;
        $company_table = $wpdb->prefix . "cr_mobile_companies";       
        $review_table  = $wpdb->prefix . "cr_mobile_reviews";     

        $sql = "DROP TABLE IF EXISTS $company_table, $review_table;";

        $wpdb->query($sql);
    }
}
